package cn.yunlang.zhangZhongFei.service.impl;

import com.alibaba.fastjson2.JSON;
import cn.yunlang.zhangZhongFei.util.WebUtils;
import cn.yunlang.zhangZhongFei.vo.response.R;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author yyl25
 */
@Component
public class AccessDeniedHandlerImpl implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) {
        R<?> error = R.error(HttpStatus.FORBIDDEN.value(), "权限不足");
        String json = JSON.toJSONString(error);
        WebUtils.renderString(response,json);
    }
}


